//缓存操作
function storage(key: string, value?: string): string;
function storage(key: string, value: boolean): void;
function storage(key: string, value?: string | boolean): any {
    if (typeof value == 'boolean') {
        value && localStorage.removeItem(key);
        return;
    }
    if (value) {
        localStorage.setItem(key, value);
        return;
    }
    return localStorage.getItem(key)!;
}

//递归解析
interface ArrFace {
    [key: string]: any
}

function recursion<T extends ArrFace>(arr: T[], key: string, target: T[]): T[] {

    if (!arr.length)
        return [];
    arr.forEach((item, index) => {
        if (item[key] && item[key].length && item['redirect']) {
            recursion(item[key], key, target);
        }
        else {
            target[target.length] = item;
        }
    })
    return target;
}


export { storage, recursion };

